package com.android.multiplesmart.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.multiplesmart.R;
import com.android.multiplesmart.bean.LanguageDataBean;

import java.util.List;

public class GridLanguageAdapter extends BaseAdapter {
    private List<LanguageDataBean> itemList; // 数据源

    public GridLanguageAdapter(List<LanguageDataBean> itemList) {
        this.itemList = itemList;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 获取或创建Item视图
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
        }
        // 设置Item视图的内容
        LanguageDataBean languageDataBean = (LanguageDataBean) getItem(position);
        TextView textView = convertView.findViewById(R.id.txt_language_name);
        textView.setText(languageDataBean.getLanguageEnName());
        convertView.setTag(languageDataBean);
        return convertView;
    }
}
